package com.wen.open.springframework.test.context;

import com.wen.open.springframework.beans.BeansException;
import com.wen.open.springframework.beans.factory.config.BeanPostProcessor;
import com.wen.open.springframework.test.bean.UserService;

/**
 * @author Wen
 * @date 2023/4/25 08:19
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof UserService) {
            UserService service = (UserService) bean;
            service.setLocation("shanghai");
            return service;
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return null;
    }
}
